﻿using System.Runtime.CompilerServices;
using KinonekoSoftware.CodariaDB.Utils;

namespace KinonekoSoftware.Studio.Models.Theories
{
    public class PseudoCatalog : ObservableObject, IHierarchicalObject
    {
        private bool   _isTargetCatalog;
        
        public  string Id       { get; init; }
        public  string ParentID { get; set; }
        public  string Name     { get; init; }
        public  int    Index    { get; set; }

        public bool IsTargetCatalog
        {
            get => _isTargetCatalog;
            set => SetValue(ref _isTargetCatalog, value);
        }
        
        public ObservableCollection<PseudoCatalog> Children { get; set; }
        
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool IsRoot() => string.IsNullOrEmpty(ParentID);
        
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool HasParent() => !string.IsNullOrEmpty(ParentID);
        
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public string GetID() => Id;
        
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public string GetParentID() => ParentID;
        
        public void AppendChild(IHierarchicalObject instance)
        {
            var instance2 = (PseudoCatalog)instance;
            Children ??= new ObservableCollection<PseudoCatalog>();

            Children.Add(instance2);
        }
    }
}